﻿<%@ Page Language="C#" MasterPageFile="~/MasterPages/Default.Master" AutoEventWireup="true"
  CodeBehind="PurchaseInfo.aspx.cs" Inherits="SaleManagement.Web.Pages.PurchaseInfo"
  Title="" %>

<%@ Register Assembly="DevExpress.Web.ASPxGridView.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxGridView" TagPrefix="dxwgv" %>
<%@ Register Assembly="DevExpress.Web.ASPxEditors.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxEditors" TagPrefix="dxe" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxCallback" TagPrefix="dxcb" %>
<%@ Register Assembly="DevExpress.Web.v9.1, Version=9.1.4.0, Culture=neutral, PublicKeyToken=5377c8e3b72b4073"
  Namespace="DevExpress.Web.ASPxPopupControl" TagPrefix="dxpc" %>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
  <div id="divContent" runat="server">
    <table width="100%">
      <tr>
        <td class="search_header">
          Thông tin hóa đơn mua hàng
        </td>
      </tr>
      <tr>
        <td style="text-align: right">
          <dxe:ASPxHyperLink ID="hlBack" runat="server" Text="Trở về" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
            CssPostfix="Aqua" Cursor="pointer">
            <ClientSideEvents Click="function(s, e) {
	onBack();
}" />
          </dxe:ASPxHyperLink>
        </td>
      </tr>
      <tr>
        <td class="insert_header">
          Thông tin khách hàng
        </td>
      </tr>
      <tr>
        <td class="formInfo">
          <table border="0" width="100%" style="padding-bottom: 20px">
            <tr>
              <td style="width: 50px">
                Mã:
              </td>
              <td style="width: 170px">
                <dxe:ASPxButtonEdit ID="btneCustomerNo" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" ImageFolder="~/App_Themes/Aqua/{0}/" ClientInstanceName="btneCustomerNo"
                  Width="170px" ReadOnly="True">
                  <ButtonEditEllipsisImage Height="3px" Url="~/App_Themes/Aqua/Editors/edtEllipsis.png"
                    UrlDisabled="~/App_Themes/Aqua/Editors/edtEllipsisDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtEllipsisHottracked.png"
                    UrlPressed="~/App_Themes/Aqua/Editors/edtEllipsisPressed.png" Width="12px" />
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" Width="14px" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                  <Buttons>
                    <dxe:EditButton>
                    </dxe:EditButton>
                  </Buttons>
                  <ClientSideEvents ButtonClick="function(s, e) {
	pcCustomer.Show();
}" />
                </dxe:ASPxButtonEdit>
              </td>
              <td class="notNullNote" style="width: 30px">
                (*)
              </td>
              <td style="width: 40px">
                Tên:
              </td>
              <td style="width: 190px">
                <dxe:ASPxTextBox ID="txtCustomerName" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="170px" ClientInstanceName="txtCustomerName">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
              <td style="width: 80px">
                Số điện thoại:
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtCustomerPhone" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="170px" ClientInstanceName="txtCustomerPhone">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                Email:
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtCustomerEmail" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="170px" ClientInstanceName="txtCustomerEmail">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
              <td>
              </td>
              <td>
                Fax:
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtCustomerFax" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="170px" ClientInstanceName="txtCustomerFax">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
            <tr>
              <td>
                Địa chỉ:
              </td>
              <td colspan="6">
                <dxe:ASPxTextBox ID="txtCustomerAddress" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="413px" ClientInstanceName="txtCustomerAddress">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td class="insert_header">
          Thông tin chung
        </td>
      </tr>
      <tr>
        <td class="formInfo">
          <table border="0" width="100%" style="padding-bottom: 20px">
            <tr>
              <td style="width: 100px">
                Mã hóa đơn:
              </td>
              <td style="width: 170px">
                <dxe:ASPxTextBox ID="txtPurchaseCode" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="170px" ClientInstanceName="txtPurchaseCode" ClientEnabled="False">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
              <td style="width: 30px">
              </td>
              <td style="width: 100px">
                Ngày mua hàng:
              </td>
              <td style="width: 170px">
                <dxe:ASPxDateEdit ID="dePurchaseDate" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" ImageFolder="~/App_Themes/Aqua/{0}/" ShowShadow="False" ClientInstanceName="dePurchaseDate"
                  Width="170px">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                  <DropDownButton>
                    <Image Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png" UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png"
                      UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" UrlPressed="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" />
                  </DropDownButton>
                  <CalendarProperties>
                    <HeaderStyle Spacing="1px" />
                    <FooterStyle Spacing="17px" />
                  </CalendarProperties>
                </dxe:ASPxDateEdit>
              </td>
              <td class="notNullNote">
                (*)
              </td>
            </tr>
            <tr>
              <td>
                Kho:
              </td>
              <td>
                <dxe:ASPxComboBox ID="cbxRepository" ClientInstanceName="cbxRepository" runat="server"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" ImageFolder="~/App_Themes/Aqua/{0}/"
                  LoadingPanelText="" ShowShadow="False" ValueType="System.Int32" TextField="Name"
                  ValueField="Id">
                  <ButtonEditEllipsisImage Height="3px" Url="~/App_Themes/Aqua/Editors/edtEllipsis.png"
                    UrlDisabled="~/App_Themes/Aqua/Editors/edtEllipsisDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtEllipsisHottracked.png"
                    UrlPressed="~/App_Themes/Aqua/Editors/edtEllipsisPressed.png" Width="12px" />
                  <DropDownButton>
                    <Image Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png" UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png"
                      UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" UrlPressed="~/App_Themes/Aqua/Editors/edtDropDownPressed.png"
                      Width="9px" />
                  </DropDownButton>
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" Width="14px" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxComboBox>
              </td>
              <td class="notNullNote">
                (*)
              </td>
              <td>
                Tổng tiền:
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtTotalMoney" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="170px" ClientInstanceName="txtTotalMoney" ClientEnabled="False">
                  <ValidationSettings Display="Dynamic">
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                  <MaskSettings IncludeLiterals="None" Mask="&lt;0..9999999999999999999g&gt;" />
                </dxe:ASPxTextBox>
              </td>
              <td class="notNullNote">
                (*)
              </td>
            </tr>
            <tr>
              <td>
                Tiền hoa hồng:
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtCommission" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="170px" ClientInstanceName="txtCommission">
                  <ValidationSettings Display="Dynamic">
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                  <MaskSettings IncludeLiterals="None" Mask="&lt;0..9999999999999999999g&gt;" />
                </dxe:ASPxTextBox>
              </td>
              <td>
              </td>
              <td>
                Trả trước:
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtPrepaid" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Width="170px" ClientInstanceName="txtPrepaid">
                  <ValidationSettings Display="Dynamic">
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                  <MaskSettings IncludeLiterals="None" Mask="&lt;0..9999999999999999999g&gt;" />
                </dxe:ASPxTextBox>
              </td>
              <td class="notNullNote">
                (*)
              </td>
            </tr>
            <tr>
              <td>
                Ghi chú:
              </td>
              <td colspan="4">
                <dxe:ASPxMemo ID="mmPurchaseNotes" runat="server" ClientInstanceName="mmPurchaseNotes"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" Height="71px"
                  Width="476px">
                  <ValidationSettings>
                    <ErrorImage Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxMemo>
              </td>
            </tr>
            <tr id="trChangeReason" runat="server">
              <td>
                Lý do chỉnh sửa:
              </td>
              <td colspan="4">
                <dxe:ASPxMemo ID="mmChangeReason" runat="server" ClientInstanceName="mmChangeReason"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" Height="71px"
                  Width="476px">
                  <ValidationSettings>
                    <ErrorImage Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxMemo>
              </td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td class="insert_header">
          Thông tin chi tiết
        </td>
      </tr>
      <tr>
        <td class="formInfo">
          <table border="0" width="100%" style="padding-bottom: 10px">
            <tr>
              <td>
                <dxwgv:ASPxGridView ID="gvPurchaseDetail" ClientInstanceName="gvPurchaseDetail" KeyFieldName="Id"
                  runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua"
                  Width="100%" EnableCallbackCompression="True" AutoGenerateColumns="False" OnCustomCallback="gvPurchaseDetail_CustomCallback"
                  OnCustomJSProperties="gvPurchaseDetail_CustomJSProperties">
                  <Styles CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  </Styles>
                  <SettingsBehavior AllowDragDrop="False" AllowGroup="False" AllowSort="False" ConfirmDelete="True" />
                  <SettingsPager PageSize="20">
                    <AllButton>
                      <Image Height="19px" Width="27px" />
                    </AllButton>
                    <FirstPageButton>
                      <Image Height="19px" Width="23px" />
                    </FirstPageButton>
                    <LastPageButton>
                      <Image Height="19px" Width="23px" />
                    </LastPageButton>
                    <NextPageButton>
                      <Image Height="19px" Width="19px" />
                    </NextPageButton>
                    <PrevPageButton>
                      <Image Height="19px" Width="19px" />
                    </PrevPageButton>
                  </SettingsPager>
                  <Images ImageFolder="~/App_Themes/Aqua/{0}/">
                    <HeaderSortDown Height="5px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortDown.png"
                      Width="7px" />
                    <ExpandedButton Height="15px" Url="~/App_Themes/Aqua/GridView/gvExpandedButton.png"
                      Width="15px" />
                    <CollapsedButton Height="15px" Url="~/App_Themes/Aqua/GridView/gvCollapsedButton.png"
                      Width="15px" />
                    <HeaderFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilter.png" Width="19px" />
                    <DetailCollapsedButton Height="15px" Url="~/App_Themes/Aqua/GridView/gvDetailCollapsedButton.png"
                      Width="15px" />
                    <DetailExpandedButton Height="15px" Url="~/App_Themes/Aqua/GridView/gvDetailExpandedButton.png"
                      Width="15px" />
                    <HeaderActiveFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilterActive.png"
                      Width="19px" />
                    <HeaderSortUp Height="5px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortUp.png" Width="7px" />
                    <FilterRowButton Height="13px" Width="13px" />
                    <WindowResizer Height="13px" Url="~/App_Themes/Aqua/GridView/WindowResizer.png" Width="13px" />
                  </Images>
                  <SettingsLoadingPanel Mode="Disabled" />
                  <StylesEditors>
                    <ProgressBar Height="25px">
                    </ProgressBar>
                  </StylesEditors>
                  <ImagesEditors>
                    <CalendarFastNavPrevYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNPrevYear.png"
                      Width="19px" />
                    <SpinEditLargeIncrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncImage.png"
                      UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png"
                      UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png" Width="7px" />
                    <SpinEditLargeDecrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecImage.png"
                      UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png"
                      UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png" Width="7px" />
                    <SpinEditIncrement Height="6px" Url="~/App_Themes/Aqua/Editors/edtSpinEditIncrementImage.png"
                      UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditIncrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png"
                      UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png"
                      Width="7px" />
                    <SpinEditDecrement Height="7px" Url="~/App_Themes/Aqua/Editors/edtSpinEditDecrementImage.png"
                      UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditDecrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png"
                      UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png"
                      Width="7px" />
                    <CalendarFastNavNextYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNNextYear.png"
                      Width="19px" />
                    <DropDownEditDropDown Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png"
                      UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png"
                      Width="9px" />
                  </ImagesEditors>
                  <ClientSideEvents EndCallback="function(s, e) {
	gvPurchaseDetail_EndCallback(s, e);
}" />
                  <Columns>
                    <dxwgv:GridViewDataColumn VisibleIndex="0" Caption="Tác vụ" Width="100px">
                      <DataItemTemplate>
                        <img alt="Cập nhật" title="Cập nhật" src="../Images/edit.png" style="cursor: pointer"
                          onclick="fillPurchaseDetail('<%#Eval("Id") %>', '<%#Eval("Code") %>', '<%#Eval("ProductGroupId") %>', '<%#Eval("ProductId") %>', '<%#Eval("Quantity") %>', '<%#Eval("Price") %>');" />
                        <img alt="Xóa" title="Xóa" src="../Images/delete.png" style="cursor: pointer" onclick="deletePurchaseDetail('<%#Eval("Id") %>', '<%#Eval("Price") %>', '<%#Eval("Quantity") %>');" />
                      </DataItemTemplate>
                      <HeaderStyle HorizontalAlign="Center" />
                      <CellStyle HorizontalAlign="Center" />
                    </dxwgv:GridViewDataColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Mã sản phẩm" FieldName="Code" VisibleIndex="1">
                      <HeaderStyle HorizontalAlign="Center" />
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn FieldName="ProductGroupId" Visible="False" VisibleIndex="2">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Nhóm sản phẩm" FieldName="ProductGroupName"
                      VisibleIndex="2">
                      <HeaderStyle HorizontalAlign="Center" />
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn FieldName="ProductId" Visible="False" VisibleIndex="3">
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Sản phẩm" FieldName="ProductName" VisibleIndex="3">
                      <HeaderStyle HorizontalAlign="Center" />
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataSpinEditColumn Caption="Số lượng" FieldName="Quantity" VisibleIndex="4">
                      <EditFormSettings VisibleIndex="1" />
                      <PropertiesSpinEdit MinValue="0" AllowNull="false" Increment="1" NumberType="Float" />
                      <HeaderStyle HorizontalAlign="Center" />
                    </dxwgv:GridViewDataSpinEditColumn>
                    <dxwgv:GridViewDataTextColumn Caption="Giá" FieldName="Price" VisibleIndex="5">
                      <HeaderStyle HorizontalAlign="Center" />
                       <PropertiesTextEdit DisplayFormatString="#,##0" />
                    </dxwgv:GridViewDataTextColumn>
                    
                  </Columns>
                  <SettingsText Title="Xác nhận" ConfirmDelete="Bạn có thật sự muốn xóa?" PopupEditFormCaption="Thêm sản phẩm" />
                </dxwgv:ASPxGridView>
              </td>
            </tr>
            <tr>
              <td>
                <dxe:ASPxButton ID="btnNew" runat="server" Text="Thêm mới" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" AutoPostBack="False">
                  <Image Url="~/Images/add.png" />
                  <ClientSideEvents Click="function(s, e) { addNewDetail();}" />
                </dxe:ASPxButton>
              </td>
            </tr>
          </table>
        </td>
      </tr>
      <tr>
        <td align="center">
          <div style="float: left; padding-left: 300px;">
            <dxe:ASPxButton ID="btnSave" runat="server" Text="Lưu" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
              CssPostfix="Aqua" AutoPostBack="False">
              <Image Url="~/Images/save.png" />
              <ClientSideEvents Click="function(s, e) { onBtnSaveClick(s, e);}" />
            </dxe:ASPxButton>
          </div>
          <div style="float: left; padding-left: 5px;">
            <dxe:ASPxButton ID="btnApprove" runat="server" Text="Approve" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
              CssPostfix="Aqua" AutoPostBack="False" ClientVisible="false">
              <Image Url="~/Images/approve.png" />
              <ClientSideEvents Click="function(s, e) { onBtnApproveClick(s, e);}" />
            </dxe:ASPxButton>
          </div>
          <div style="float: left; padding-left: 5px;">
            <dxe:ASPxButton ID="btnReject" runat="server" Text="Reject" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
              CssPostfix="Aqua" AutoPostBack="False" ClientVisible="false">
              <Image Url="~/Images/reject.png" />
              <ClientSideEvents Click="function(s, e) { onBtnRejectClick(s, e);}" />
            </dxe:ASPxButton>
          </div>
        </td>
      </tr>
    </table>
    <dxpc:ASPxPopupControl ID="pcPurchaseDetail" runat="server" ClientInstanceName="pcPurchaseDetail"
      CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" HeaderText="Thông tin chi tiết hóa đơn"
      ImageFolder="~/App_Themes/Aqua/{0}/" Modal="True" PopupHorizontalAlign="WindowCenter"
      PopupVerticalAlign="WindowCenter">
      <ContentStyle VerticalAlign="Top">
      </ContentStyle>
      <SizeGripImage Height="12px" />
      <ContentCollection>
        <dxpc:PopupControlContentControl runat="server">
          <table width="580px" border="0">
            <tr>
              <td style="width: 100px">
                Nhóm sản phẩm:
              </td>
              <td style="width: 170px">
                <dxe:ASPxComboBox ID="cbxProductGroup" ClientInstanceName="cbxProductGroup" runat="server"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" ImageFolder="~/App_Themes/Aqua/{0}/"
                  LoadingPanelText="" ShowShadow="False" ValueType="System.Int32" Width="170px" TextField="Name"
                  ValueField="Id">
                  <ClientSideEvents ValueChanged="function(s, e) {
	cbxProductGroup_ValueChanged();
}" />
                  <DropDownButton>
                    <Image Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png" UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png"
                      UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" UrlPressed="~/App_Themes/Aqua/Editors/edtDropDownPressed.png" />
                  </DropDownButton>
                  <ButtonEditEllipsisImage Height="3px" Url="~/App_Themes/Aqua/Editors/edtEllipsis.png"
                    UrlDisabled="~/App_Themes/Aqua/Editors/edtEllipsisDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtEllipsisHottracked.png"
                    UrlPressed="~/App_Themes/Aqua/Editors/edtEllipsisPressed.png" />
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxComboBox>
              </td>
              <td class="notNullNote" style="width: 30px">
                (*)
              </td>
              <td style="width: 80px">
                Sản phẩm:
              </td>
              <td style="width: 170px">
                <dxe:ASPxComboBox ID="cbxProduct" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" ImageFolder="~/App_Themes/Aqua/{0}/" LoadingPanelText="" ShowShadow="False"
                  ValueType="System.Int32" Width="170px" ClientInstanceName="cbxProduct" TextField="Name"
                  ValueField="Id" OnCallback="cbxProduct_Callback" OnCustomJSProperties="cbxProduct_CustomJSProperties">
                  <ClientSideEvents EndCallback="function(s, e) {
	cbxProduct_EndCallback(s, e);
}" ValueChanged="function(s, e) {
	cbxProduct_ValueChanged();
}" />
                  <DropDownButton>
                    <Image Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png" UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png"
                      UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" UrlPressed="~/App_Themes/Aqua/Editors/edtDropDownPressed.png" />
                  </DropDownButton>
                  <ButtonEditEllipsisImage Height="3px" Url="~/App_Themes/Aqua/Editors/edtEllipsis.png"
                    UrlDisabled="~/App_Themes/Aqua/Editors/edtEllipsisDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtEllipsisHottracked.png"
                    UrlPressed="~/App_Themes/Aqua/Editors/edtEllipsisPressed.png" />
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxComboBox>
              </td>
              <td class="notNullNote">
                (*)
              </td>
            </tr>
            <tr>
              <td>
                Số lượng:
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtDetailQuantity" runat="server" ClientInstanceName="txtDetailQuantity"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css"  CssPostfix="Aqua" Width="170px">
                  <MaskSettings  IncludeLiterals="DecimalSymbol" Mask="<0..9999999999999999999>.<0..9>" />
                  <ValidationSettings Display="Dynamic">
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
              <td>
              </td>
              <td>
                Giá:
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtDetailPrice" runat="server" ClientInstanceName="txtDetailPrice"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" Width="170px">
                  <MaskSettings IncludeLiterals="None" Mask="&lt;0..9999999999999999999g&gt;" />
                  <ValidationSettings Display="Dynamic">
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
              <td>
              </td>
            </tr>
            <tr id="trDetailCodeNote" runat="server" style="display: none">
              <td valign="top">
                Mã sản phẩm:
                <br />
                <div class="note_gray">
                  (
                  <dxe:ASPxLabel ID="lblDetailCodeNumber" ClientInstanceName="lblDetailCodeNumber"
                    runat="server" Text="0" CssClass="note_gray">
                  </dxe:ASPxLabel>
                  )
                </div>
              </td>
              <td colspan="4">
                <dxe:ASPxMemo ID="mmDetailCode" runat="server" ClientInstanceName="mmDetailCode"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" Height="71px"
                  Width="100%">
                  <ValidationSettings>
                    <ErrorImage Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                  <ClientSideEvents KeyUp="function(s, e){ mmDetailCode_KeyUp();}" />
                </dxe:ASPxMemo>
              </td>
              <td class="notNullNote" valign="top">
                (*)
              </td>
            </tr>
            <tr>
              <td colspan="6" align="center" style="padding-top: 10px">
                <table>
                  <tr>
                    <td>
                      <dxe:ASPxButton ID="btnDetailSave" runat="server" Text="Lưu" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                        CssPostfix="Aqua" AutoPostBack="False">
                        <Image Url="~/Images/save.png" />
                        <ClientSideEvents Click="function(s, e) { onBtnDetailSaveClick();}" />
                      </dxe:ASPxButton>
                    </td>
                    <td>
                      <dxe:ASPxButton ID="btnDetailCancel" runat="server" Text="Hủy" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                        CssPostfix="Aqua" AutoPostBack="False">
                        <Image Url="~/Images/undo.gif" />
                        <ClientSideEvents Click="function(s, e) { pcPurchaseDetail.Hide();}" />
                      </dxe:ASPxButton>
                    </td>
                  </tr>
                </table>
              </td>
            </tr>
          </table>
        </dxpc:PopupControlContentControl>
      </ContentCollection>
      <CloseButtonImage Height="16px" />
      <HeaderStyle Font-Bold="True" ForeColor="#59A1EF" />
    </dxpc:ASPxPopupControl>
    <dxpc:ASPxPopupControl ID="pcCustomer" runat="server" ClientInstanceName="pcCustomer"
      CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" HeaderText="Tìm kiếm khách hàng"
      ImageFolder="~/App_Themes/Aqua/{0}/" Modal="True" PopupHorizontalAlign="WindowCenter"
      PopupVerticalAlign="WindowCenter">
      <ContentStyle VerticalAlign="Top">
      </ContentStyle>
      <SizeGripImage Height="12px" />
      <ContentCollection>
        <dxpc:PopupControlContentControl ID="PopupControlContentControl1" runat="server">
          <table width="700px" border="0">
            <tr>
              <td style="height: 19px">
                Mã KH:
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtSearchCode" runat="server" Width="120px" ClientInstanceName="txtSearchCode"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
              <td>
                Tên KH:
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtSearchName" runat="server" Width="120px" ClientInstanceName="txtSearchName"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
              <td>
                Số điện thoại:
              </td>
              <td>
                <dxe:ASPxTextBox ID="txtSearchPhone" runat="server" Width="120px" ClientInstanceName="txtSearchPhone"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  <ValidationSettings>
                    <ErrorImage Height="14px" Url="~/App_Themes/Aqua/Editors/edtError.png" />
                    <ErrorFrameStyle ImageSpacing="4px">
                      <ErrorTextPaddings PaddingLeft="4px" />
                    </ErrorFrameStyle>
                  </ValidationSettings>
                </dxe:ASPxTextBox>
              </td>
              <td>
                <dxe:ASPxButton ID="btnCustomerSearch" runat="server" CssFilePath="~/App_Themes/Aqua/{0}/styles.css"
                  CssPostfix="Aqua" Text="Tìm kiếm">
                  <Image Url="~/Images/find.png" />
                  <ClientSideEvents Click="function(s,e){searchCustomer();e.processOnServer=false;}" />
                </dxe:ASPxButton>
              </td>
            </tr>
            <tr>
              <td colspan="7" style="padding-top: 10px">
                <dxwgv:ASPxGridView ID="gvCustomer" runat="server" Width="100%" AutoGenerateColumns="False"
                  CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua" KeyFieldName="Id"
                  OnCustomCallback="gvCustomer_CustomCallback" OnPageIndexChanged="gvCustomer_PageIndexChanged"
                  ClientInstanceName="gvCustomer">
                  <SettingsBehavior AllowDragDrop="false" AllowSort="false" AllowGroup="False" />
                  <Columns>
                    <dxwgv:GridViewDataTextColumn VisibleIndex="0" Caption="Mã khách hàng" FieldName="CustomerNo">
                      <DataItemTemplate>
                        <a onclick="selectCustomer('<%#Eval("Id") %>', '<%#Eval("Name") %>', '<%#Eval("CustomerNo") %>', '<%#Eval("Phone") %>', '<%#Eval("Email") %>', '<%#Eval("Fax") %>', '<%#Eval("Address") %>');">
                          <%#Eval("CustomerNo")%></a>
                      </DataItemTemplate>
                      <HeaderStyle HorizontalAlign="Center" />
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn FieldName="Name" VisibleIndex="1" Caption="Tên khách hàng">
                      <HeaderStyle HorizontalAlign="Center" />
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn FieldName="Phone" VisibleIndex="1" Caption="Điện thoại">
                      <HeaderStyle HorizontalAlign="Center" />
                      <CellStyle HorizontalAlign="Right">
                      </CellStyle>
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataTextColumn FieldName="Fax" Caption="Fax" VisibleIndex="2">
                      <HeaderStyle HorizontalAlign="Center" />
                      <CellStyle HorizontalAlign="Right">
                      </CellStyle>
                    </dxwgv:GridViewDataTextColumn>
                    <dxwgv:GridViewDataMemoColumn FieldName="Address" VisibleIndex="4" Caption="Địa chỉ">
                      <HeaderStyle HorizontalAlign="Center" />
                    </dxwgv:GridViewDataMemoColumn>
                    <dxwgv:GridViewDataTextColumn FieldName="Email" VisibleIndex="5" Caption="Email">
                      <HeaderStyle HorizontalAlign="Center" />
                    </dxwgv:GridViewDataTextColumn>
                  </Columns>
                  <Images ImageFolder="~/App_Themes/Aqua/{0}/">
                    <HeaderSortDown Height="5px" Width="6px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortDown.png" />
                    <CollapsedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvCollapsedButton.png" />
                    <ExpandedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvExpandedButton.png" />
                    <DetailCollapsedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvDetailCollapsedButton.png" />
                    <DetailExpandedButton Height="15px" Width="13px" Url="~/App_Themes/Aqua/GridView/gvDetailExpandedButton.png" />
                    <HeaderFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilter.png" Width="19px" />
                    <HeaderActiveFilter Height="19px" Url="~/App_Themes/Aqua/GridView/gvHeaderFilterActive.png"
                      Width="19px" />
                    <HeaderSortUp Height="5px" Width="6px" Url="~/App_Themes/Aqua/GridView/gvHeaderSortUp.png" />
                    <FilterRowButton Height="13px" Width="13px" />
                    <CustomizationWindowClose Width="18px" />
                    <PopupEditFormWindowClose Width="18px" />
                    <WindowResizer Height="13px" Width="12px" Url="~/App_Themes/Aqua/GridView/WindowResizer.png" />
                    <FilterBuilderClose Width="18px" />
                  </Images>
                  <StylesEditors>
                    <ProgressBar Height="25px">
                    </ProgressBar>
                  </StylesEditors>
                  <ImagesEditors>
                    <CalendarPrevYear Width="23px" />
                    <CalendarPrevMonth Width="19px" />
                    <CalendarNextMonth Width="19px" />
                    <CalendarNextYear Width="23px" />
                    <CalendarFastNavPrevYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNPrevYear.png" />
                    <CalendarFastNavNextYear Height="19px" Url="~/App_Themes/Aqua/Editors/edtCalendarFNNextYear.png" />
                    <DropDownEditDropDown Height="7px" Url="~/App_Themes/Aqua/Editors/edtDropDown.png"
                      UrlDisabled="~/App_Themes/Aqua/Editors/edtDropDownDisabled.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtDropDownHottracked.png" />
                    <SpinEditIncrement Height="6px" Url="~/App_Themes/Aqua/Editors/edtSpinEditIncrementImage.png"
                      UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditIncrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png"
                      UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditIncrementHottrackedImage.png" />
                    <SpinEditDecrement Height="7px" Url="~/App_Themes/Aqua/Editors/edtSpinEditDecrementImage.png"
                      UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditDecrementDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png"
                      UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditDecrementHottrackedImage.png" />
                    <SpinEditLargeIncrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncImage.png"
                      UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png"
                      UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeIncHottrackedImage.png" />
                    <SpinEditLargeDecrement Height="9px" Url="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecImage.png"
                      UrlDisabled="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecDisabledImage.png" UrlHottracked="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png"
                      UrlPressed="~/App_Themes/Aqua/Editors/edtSpinEditLargeDecHottrackedImage.png" />
                  </ImagesEditors>
                  <Styles CssFilePath="~/App_Themes/Aqua/{0}/styles.css" CssPostfix="Aqua">
                  </Styles>
                  <SettingsLoadingPanel Text="" />
                  <SettingsPager>
                    <AllButton>
                      <Image Height="19px" Width="28px" />
                    </AllButton>
                    <FirstPageButton>
                      <Image Height="19px" Width="23px" />
                    </FirstPageButton>
                    <LastPageButton>
                      <Image Height="19px" Width="23px" />
                    </LastPageButton>
                    <NextPageButton>
                      <Image Height="19px" Width="19px" />
                    </NextPageButton>
                    <PrevPageButton>
                      <Image Height="19px" Width="19px" />
                    </PrevPageButton>
                  </SettingsPager>
                </dxwgv:ASPxGridView>
              </td>
            </tr>
          </table>
        </dxpc:PopupControlContentControl>
      </ContentCollection>
      <CloseButtonImage Height="16px" />
      <HeaderStyle Font-Bold="True" ForeColor="#59A1EF" />
    </dxpc:ASPxPopupControl>
    <asp:HiddenField ID="hfCustomerId" runat="server" />
    <asp:HiddenField ID="hfPurchaseId" runat="server" />
    <asp:HiddenField ID="hfDetailId" runat="server" />
    <asp:HiddenField ID="hfDetailCode" runat="server" />
    <dxcb:ASPxCallback ID="cbPurchase" runat="server" ClientInstanceName="cbPurchase"
      OnCallback="cbPurchase_Callback">
      <ClientSideEvents CallbackComplete="function(s, e) {
	cbPurchase_CallbackComplete(s, e);
}" />
    </dxcb:ASPxCallback>
  </div>

  <script type="text/javascript" language="javascript">
    var oldDetailMoney = 0;
    var editedProductId = null;

    function onBack() {
      window.location.href = "PurchaseList.aspx";
    }

    function searchCustomer() {
      gvCustomer.PerformCallback('Search|');
    }

    function selectCustomer(id, name, no, phone, email, fax, address) {
      pcCustomer.Hide();
      document.getElementById('<%=hfCustomerId.ClientID %>').value = id;
      btneCustomerNo.SetText(no);
      txtCustomerName.SetText(name);
      txtCustomerPhone.SetText(phone);
      txtCustomerEmail.SetText(email);
      txtCustomerFax.SetText(fax);
      txtCustomerAddress.SetText(address);
    }

    function addNewDetail() {
      fillPurchaseDetail('', '', '', '', 0, 0);
    }

    function checkCommonPara() {
      if (btneCustomerNo.GetText() == '') {
        alert('Vui lòng nhập tên khách hàng.');
        return false;
      }

      if (dePurchaseDate.GetValue() == null) {
        alert('Vui lòng nhập ngày mua hàng.');
        return false;
      }

      if (cbxRepository.GetValue() == null) {
        alert('Vui lòng nhập kho hàng.');
        return false;
      }

      if (txtPrepaid.GetValue() == '') {
        alert('Vui lòng nhập tiền trả trước (kể cả 0).');
        return false;
      }

      if (parseInt(txtTotalMoney.GetValue()) < parseInt(txtPrepaid.GetValue())) {
        alert('Tiền trả trước không được lớn hơn tổng tiền.');
        return false;
      }

      var purchaseId = document.getElementById('<%=hfPurchaseId.ClientID %>').value;
      if (purchaseId != '' && purchaseId != null) {
        if (trim(mmChangeReason.GetText()) == '') {
          alert('Vui lòng nhập lý do chỉnh sửa.');
          return false;
        }
      }

      return true;
    }

    function checkDetailPara() {
      if (txtDetailQuantity.GetValue() <= 0) {
        alert('Số lượng sản phẩm phải lớn hơn 0.');
        return false;
      }

      if (cbxProductGroup.GetValue() == null) {
        alert('Vui lòng nhập loại sản phẩm.');
        return false;
      }

      if (cbxProduct.GetValue() == null) {
        alert('Vui lòng nhập sản phẩm.');
        return false;
      }

      if (txtDetailPrice.GetValue() <= 0) {
        alert('Giá sản phẩm phải lớn hơn 0.');
        return false;
      }

      var trDetailCodeNote = document.getElementById('<%=trDetailCodeNote.ClientID %>');
      if (trDetailCodeNote.style.display != 'none') {
        if (parseInt(lblDetailCodeNumber.GetValue()) != parseInt(txtDetailQuantity.GetValue())) {
          alert('Số mã sản phẩm ít/nhiều hơn số sản phẩm.');
          return false;
        }

        var codeList = document.getElementById('<%=hfDetailCode.ClientID %>').value.split(',');
        for (var i = 0; i < codeList.length; i++) {
          for (var j = 0; j < codeList.length; j++) {
            if (i != j && codeList[i] == codeList[j]) {
              alert('Mã sản phẩm \'' + codeList[i] + '\' đã được nhập nhiều hơn 1 lần');
              return false;
            }
          }
        }
      }

      return true;
    }

    function cbxProductGroup_ValueChanged() {
      cbxProduct.ClearItems();
      cbxProduct.PerformCallback('LoadProduct');
    }

    function cbxProduct_ValueChanged() {
      cbPurchase.PerformCallback('LoadProductPrice');
    }

    function cbPurchase_CallbackComplete(s, e) {
      txtDetailPrice.SetValue(e.result);
    }

    function cbxProduct_EndCallback(s, e) {
      cbxProduct.SetValue(editedProductId);
      var trDetailCodeNote = document.getElementById('<%=trDetailCodeNote.ClientID %>');
      var detailId = document.getElementById('<%=hfDetailId.ClientID %>').value;
      if (cbxProduct.cpInnerError == 'IsInventory') {
        trDetailCodeNote.style.display = '';
        if (detailId != '') {
          txtDetailQuantity.SetValue('1');
          txtDetailQuantity.SetEnabled(false);
        }
      }
      else {
        trDetailCodeNote.style.display = 'none';
        txtDetailQuantity.SetEnabled(true);
      }
    }

    function fillPurchaseDetail(id, code, productGroupId, productId, quantity, price) {
      document.getElementById('<%=hfDetailId.ClientID %>').value = id;
      document.getElementById('<%=hfDetailCode.ClientID %>').value = '';
      mmDetailCode.SetText('');
      lblDetailCodeNumber.SetValue(0);
      cbxProductGroup.SetValue(productGroupId);
      editedProductId = productId;
      cbxProductGroup_ValueChanged();
      txtDetailQuantity.SetValue(quantity);
      txtDetailPrice.SetValue(price);
      oldDetailMoney = parseInt(price) * parseInt(quantity);
      if (isNaN(oldDetailMoney)) {
        oldDetailMoney = 0;
      }

      pcPurchaseDetail.Show();
    }

    function deletePurchaseDetail(id, price, quantity) {
      if (confirm('Bạn có thật sự muốn xóa không?')) {
        oldDetailMoney = parseInt(price) * parseInt(quantity);
        if (isNaN(oldDetailMoney)) {
          oldDetailMoney = 0;
        }

        pcWaiting.Show();
        gvPurchaseDetail.PerformCallback('DeleteDetail|' + id);
      }
    }

    function onBtnDetailSaveClick() {
      if (checkDetailPara()) {
        pcWaiting.Show();
        gvPurchaseDetail.PerformCallback('SaveDetail');
      }
    }

    function onBtnSaveClick(s, e) {
      if (checkCommonPara()) {
        pcWaiting.Show();
        gvPurchaseDetail.PerformCallback('Save');
      }
    }

    function onBtnApproveClick() {
      pcWaiting.Show();
      gvPurchaseDetail.PerformCallback('Approve');
    }

    function onBtnRejectClick() {
      alert('Hóa đơn sẽ được xóa hết các phần đã chỉnh sửa.');
      pcWaiting.Show();
      gvPurchaseDetail.PerformCallback('Reject');
    }

    function gvPurchaseDetail_EndCallback(s, e) {
      pcWaiting.Hide();
      var error = gvPurchaseDetail.cpInnerError.split('|');
      switch (error[0]) {
        case 'Save':
          document.getElementById('<%=hfCustomerId.ClientID %>').value = error[1];
          btneCustomerNo.SetText(error[2]);
          document.getElementById('<%=hfPurchaseId.ClientID %>').value = error[3];
          txtPurchaseCode.SetText(error[4]);
          txtPrepaid.SetEnabled(false);
          alert('Dữ liệu đã được cập nhật thành công.');
          window.location.href = 'PurchaseList.aspx';
          break;
        case 'Approve':
        case 'Reject':
          alert('Dữ liệu đã được cập nhật thành công.');
          window.location.href = 'PurchaseList.aspx';
          break;
        case 'SaveDetail':
        debugger
          var totalMoney = parseFloat(txtTotalMoney.GetValue());
          var newDetailMoney = parseFloat(txtDetailPrice.GetValue()) * parseFloat(txtDetailQuantity.GetValue().replace(",","."));
          txtTotalMoney.SetValue(String(totalMoney + newDetailMoney - oldDetailMoney));
          pcPurchaseDetail.Hide();
          break;
        case 'DeleteDetail':
          var totalMoney = parseInt(txtTotalMoney.GetValue());
          txtTotalMoney.SetValue(String(totalMoney - oldDetailMoney));
          break;
        default:
          alert(error[0]);
          break;
      }
    }

    function splitDetailCode(text) {
      var codeAmount = 0;
      var tempList = text.split('\n');
      var codeList = new Array();
      for (var i = 0; i < tempList.length; i++) {
        var item = trim(tempList[i]);
        if (item != null && item != '') {
          if (item.toString().indexOf('-') > 0) {
            var subTempList = item.split('-');
            if (subTempList != null && subTempList.length > 1) {
              var fromNo = parseInt(subTempList[0]);
              var toNo = parseInt(subTempList[1]);
              for (var j = fromNo; j <= toNo; j++) {
                codeList.push(j.toString());
                codeAmount++;
              }
            }
          }
          else {
            codeList.push(item);
            codeAmount++;
          }
        }
      }

      lblDetailCodeNumber.SetValue(codeAmount);
      return codeList.toString();
    }

    function mmDetailCode_KeyUp() {
      document.getElementById('<%=hfDetailCode.ClientID %>').value = splitDetailCode(mmDetailCode.GetText());
    }

    function trim(stringToTrim) {
      return stringToTrim.replace(/^\s+|\s+$/g, "");
    }
  </script>

</asp:Content>
